package com.iwhalecloud.citybrain.flow.platform.manager;

import org.flowable.engine.common.impl.cfg.IdGenerator;
import org.flowable.engine.common.impl.persistence.StrongUuidGenerator;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;

/**
 * @author lilh
 * @date 2019-01-20 08:57
 */
@EnableAsync
@SpringBootApplication
@MapperScan(basePackages = "com.iwhalecloud.citybrain.flow.platform.manager.infrastructure.mapper")
@RefreshScope
@EnableFeignClients
public class FlowEngineApplication {

    private  static  Logger  logger = LoggerFactory.getLogger(FlowEngineApplication.class);

    public static void main(String[] args) {
        ConfigurableApplicationContext applicationContext = SpringApplication.run(FlowEngineApplication.class, args);
        DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory)applicationContext.getBeanFactory();
        String[] beannames = beanFactory.getBeanDefinitionNames();
        for(String beanname : beannames){
            Object bean =  beanFactory.getBean(beanname);
            //logger.info("Beanname:"+beanname+ " BeanClass:"+bean.getClass().getName());
        }
        logger.info("Flow Application Started Succ...");
    }

    @Bean
    public IdGenerator uuidGenerator() {
        return new StrongUuidGenerator() {
            @Override
            public String getNextId() {
                return super.getNextId().replaceAll("-", "");
            }
        };
    }
}
